<template>
  <div style="padding-top: 100px;padding-left: 200px;">
    <div style="width: 25%;padding-top: 20px;background: #B3C0D1;height: 30%" >
      <el-tag>博思登录页面</el-tag>
      <el-form :model="user" :rules="rules" ref="loginForm" label-width="100px" >
        <el-form-item label="账号" prop="username">
          <el-input v-model="user.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input type="password" v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
          <el-button @click="resetForm('loginForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        user: {
          username: '',
          password:'',
        },
        rules:{
          username: [
            {required:true,message:'账号不能为空',trigger:'blur'},//trigger触发事件
            {min:3,max:5,message: '长度在3到5个字符',trigger: 'blur'}
          ],
          password: [
            {required:true,message:'请输入密码',trigger:'change'}

          ],
        }
      }
    },
    methods: {

      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            //使用axios 发送ajax进行登录 后端
            if(this.user.password==123 && this.user.username=="admin"){
              this.$router.push("/")
            }else alert('密码或账号错误！');

          } else {
            console.log('error submit!!');
            return false;
          }
        });t
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>

<style scoped>

</style>
